package com.hcinfos.gsoo.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hcinfos.gsoo.R;
import com.hcinfos.gsoo.enity.Comment;

public class CommentAdapter extends BaseAdapter {

	public Context context;
	private List<Comment> list;
	private LayoutInflater mInflater;

	public CommentAdapter(Context context, List<Comment> list) {

		this.list = list;
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}

	@Override
	public int getCount() {

		return list.size();
	}

	@Override
	public Object getItem(int position) {

		return list.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		CommentHodler holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.comment_list_item, null);
			holder = new CommentHodler();
			holder.nickTv = (TextView) convertView.findViewById(R.id.nickname);
			holder.msgTv = (TextView) convertView.findViewById(R.id.msg);
			holder.timeTv = (TextView) convertView.findViewById(R.id.time);
			holder.qos = (TextView) convertView.findViewById(R.id.qos);// 口味
			holder.qstc = (TextView) convertView.findViewById(R.id.qstc);//
			holder.ambiance = (TextView) convertView
					.findViewById(R.id.ambiance);// 环境
			holder.taste = (TextView) convertView.findViewById(R.id.taste);
			convertView.setTag(holder);
		} else {
			holder = (CommentHodler) convertView.getTag();
		}
		Comment comment = list.get(position);
		Double score1 = comment.getScore1();// 口味
		Double score2 = comment.getScore2();// 环境
		Double score3 = comment.getScore3();// 服务
		String score1Str, score2Str, score3Str;
		if (score1 == null) {
			score1Str = "口味:暂无";
		} else {
			score1Str = comment.getScore1() + "";
		}
		if (score2 == null) {
			score2Str = " 环境:暂无";
		} else {
			score2Str = comment.getScore2() + "";
		}
		if (score3 == null) {
			score3Str = " 服务:暂无";
		} else {
			score3Str = comment.getScore3() + "";
		}
		holder.qos.setText("口味:" + score1Str);
		holder.qstc.setText(" 环境" + score2Str);
		holder.ambiance.setText(" 服务:" + score3Str);
		holder.timeTv.setText(comment.getAddDatetime());
		holder.nickTv.setText(comment.getUserNick());
		holder.msgTv.setText(comment.getComment());
		return convertView;
	}

	private final class CommentHodler {
		TextView nickTv;
		TextView msgTv;
		TextView timeTv;
		TextView qstc;
		TextView qos;
		TextView ambiance;
		TextView taste;
	}

	public void setDataChange(List<Comment> list) {

		this.list = list;
		notifyDataSetChanged();
	}

}
